package hczc.longcai.com.hccrowdfunding.home.fourth_mine.adapters;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.application.BaseApplication;
import hczc.longcai.com.hccrowdfunding.home.fourth_mine.FourthFragment;
import hczc.longcai.com.hccrowdfunding.home.fourth_mine.beans.RewardOrders;
import hczc.longcai.com.hccrowdfunding.home.second_invest.activities.PayActivity;

/**
 * Created by Administrator on 2016/1/27.
 */
public class RewardOrdersAdapter extends BaseAdapter implements View.OnTouchListener {

    private static final String TAG = "RewardOrdersAdapter";
    private Context context;
    private List<RewardOrders> list;


    private int state;


    public RewardOrdersAdapter(Context context, List<RewardOrders> list, int state) {
        this.context = context;
        this.list = list;
        this.state = state;
//        Log.d(TAG,"state = " + state);
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_reward_orders, null);
            BaseApplication.scaleScreenHelper.loadView(((ViewGroup) convertView));
            holder.title = ((TextView) convertView.findViewById(R.id.item_reward_orders_title));
            holder.money = ((TextView) convertView.findViewById(R.id.item_reward_orders_money));
            holder.orderNumber = ((TextView) convertView.findViewById(R.id.item_reward_orders_ordernumber));
            holder.button_pay = ((TextView) convertView.findViewById(R.id.item_reward_orders_pay));
            holder.button_enter = ((TextView) convertView.findViewById(R.id.item_reward_orders_enter));
            holder.head = ((ImageView) convertView.findViewById(R.id.item_reward_orders_pic));
            convertView.setTag(holder);
        }
        holder = ((ViewHolder) convertView.getTag());
        switch (state) {
            case FourthFragment.STATE_ALL:
//                Log.d(TAG,"全部订单");
                holder.button_pay.setVisibility(View.VISIBLE);
                holder.button_pay.setOnTouchListener(this);
                holder.button_enter.setVisibility(View.GONE);
                break;

            case FourthFragment.STATE_DZF:
//                Log.d(TAG,"待支付");
                holder.button_pay.setVisibility(View.VISIBLE);
                holder.button_pay.setOnTouchListener(this);
                holder.button_enter.setVisibility(View.GONE);
                break;

            case FourthFragment.STATE_DFH:
//                Log.d(TAG,"待发货");
                holder.button_pay.setVisibility(View.GONE);
                holder.button_enter.setVisibility(View.GONE);
                break;

            case FourthFragment.STATE_DSH:
//                Log.d(TAG,"待收货");
                holder.button_pay.setVisibility(View.GONE);
                holder.button_enter.setVisibility(View.VISIBLE);
                holder.button_enter.setOnTouchListener(this);
                break;
        }


        return convertView;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int action = event.getAction();
        TextView textView = (TextView) v;


        switch (action) {

            case MotionEvent.ACTION_DOWN:
                textView.setTextColor(Color.WHITE);
                textView.setBackgroundResource(R.mipmap.zhifu_h);
                break;

            case MotionEvent.ACTION_CANCEL:
                textView.setTextColor(Color.parseColor("#ff6a6b"));
                textView.setBackgroundResource(R.mipmap.zhifu);
                break;

            case MotionEvent.ACTION_UP:
                textView.setTextColor(Color.parseColor("#ff6a6b"));
                textView.setBackgroundResource(R.mipmap.zhifu);
                break;

        }

        return true;
    }


    class ViewHolder {

        TextView title, money, orderNumber, button_pay, button_enter;
        ImageView head;

    }
}
